//
//  WZMDialogTool.swift
//  AIPhotoProcess
//
//  Created by aw031 on 17/10/2025.
//

import Foundation
import UIKit
import WMZDialog
import SnapKit

struct WZMDialogTool {
     //MARK: -- 全屏弹窗
    static func showCenterSubViewAlertView(subView : UIView , parentView : UIView? , tag : Int = 1015) -> WMZDialog {
        
        let closeBtn = UIButton(type: .custom)
        closeBtn.setCustomBackgroundImage(KImage("greenCloseIcon"))
        closeBtn.addEventTouchBlock { btn in
            WMZDialog.closeWithshowView(nil, tag: 1015)
        }
        
        let dialog = WMZDialog()
        dialog.wType = DialogTypeMyView
        dialog.wWidth = KScreenWidth
        dialog.height = KScreenHeight
        dialog.wTag = tag
        dialog.wMainRadius = KScreenWValue(15)
//        dialog.wMainShadowShow = true
        dialog.wShowAnimation = AninatonZoomInCombin
        dialog.wHideAnimation = AninatonZoomOut
        
        
        dialog.wMyDiaLogView = { (mainView: UIView?) -> UIView? in
            
            guard let mainView = mainView else { return UIView() }
            mainView.backgroundColor = ColorWhite
            mainView.setViewWithShadowColorBlackAlpha03()
            mainView.layer.cornerRadius = KScreenWValue(15)
            
            mainView.addSubview(subView)
            let bottomLineView = UIView()
            bottomLineView.translatesAutoresizingMaskIntoConstraints = false
            mainView.addSubview(bottomLineView)
            bottomLineView.snp.makeConstraints { make in
                make.leading.trailing.equalTo(0)
                make.top.equalTo(subView.snp.bottom)
                make.height.equalTo(0)
            }
            return bottomLineView
        }
        
        if let superView = parentView {
            return dialog.wStartView(superView)

        }
        return dialog.wStart()
    }
    
    
    static func showCenterAlertView(parentView : UIView? , clickBlock : DialogClickBlock?) -> WMZDialog {
            
        let viewTag = 1015
        let dialog = WMZDialog()
        dialog.wType = DialogTypeMyView
        dialog.wWidth = KScreenWidth - KScreenWValue(60)
        dialog.wTag = viewTag
        dialog.wMainRadius = KScreenWValue(15)
//        dialog.wMainShadowShow = true

        dialog.wShowAnimation = AninatonZoomInCombin
        dialog.wHideAnimation = AninatonZoomOut
        dialog.wMyDiaLogView = { (mainView: UIView?) -> UIView? in
            
            guard let mainView = mainView else { return UIView() }
            mainView.backgroundColor = ColorWhite
            mainView.setViewWithShadowColorBlackAlpha03()
            mainView.layer.cornerRadius = KScreenWValue(15)
            
            let titleLB = UILabel()
            titleLB.font = FontMediumScale(18)
            titleLB.textColor = ColorBlack
            titleLB.textAlignment = .center
            titleLB.numberOfLines = 1
            titleLB.adjustsFontSizeToFitWidth = true
            titleLB.text = "Tip"
            mainView.addSubview(titleLB)

            let contentLB = UILabel()
            contentLB.font = FontScale(18)
            contentLB.textColor = Color666666
            contentLB.textAlignment = .center
            contentLB.numberOfLines = 0
            contentLB.text = KClickBackTip
            mainView.addSubview(contentLB)

            
            let horLineView = UIView()
            horLineView.backgroundColor = ColorBlack.withAlphaComponent(0.1)
            mainView.addSubview(horLineView)

            let verticalLineView = UIView()
            verticalLineView.backgroundColor = ColorBlack.withAlphaComponent(0.1)
            mainView.addSubview(verticalLineView)
                        
            let cancelBtn = UIButton(type: .custom)
            cancelBtn.setTitle("Save", for: .normal)
            cancelBtn.setTitleColor(Color666666, for: .normal)
            cancelBtn.addEventTouchBlock { btn in
                clickBlock?(0,viewTag)
            }
            
            let sureBtn = UIButton(type: .custom)
            sureBtn.setTitle("Sure", for: .normal)
            sureBtn.setTitleColor(ColorD75D5D, for: .normal)
            sureBtn.addEventTouchBlock { btn in
                clickBlock?(0,viewTag)
            }
            
            
            mainView.addSubview(titleLB)
            mainView.addSubview(contentLB)
            
            mainView.addSubview(horLineView)
            mainView.addSubview(verticalLineView)
            
            mainView.addSubview(cancelBtn)
            mainView.addSubview(sureBtn)


            
            titleLB.snp.makeConstraints { make in
                make.top.equalToSuperview().offset(KScreenWValue(10))
                make.height.equalTo(KScreenWValue(37))
                make.leading.equalTo(KScreenWValue(10))
                make.trailing.equalTo(-KScreenWValue(10))
            }
            
            
            contentLB.snp.makeConstraints { make in
                make.top.equalTo(titleLB.snp.bottom).offset(KScreenWValue(14))
                make.leading.trailing.equalTo(titleLB)
            }
            
            
            horLineView.snp.makeConstraints { make in
                make.top.equalTo(contentLB.snp.bottom).offset(KScreenWValue(12))
                make.leading.trailing.equalToSuperview()
                make.height.equalTo(1)
            }
            
            verticalLineView.snp.makeConstraints { make in
                make.top.equalTo(horLineView.snp.bottom)
                make.centerX.equalToSuperview()
                make.width.equalTo(1)
                make.bottom.equalTo(cancelBtn.snp.bottom)
            }

            cancelBtn.snp.makeConstraints { make in
                make.top.equalTo(horLineView.snp.bottom)
                make.leading.equalToSuperview()
                make.trailing.equalTo(verticalLineView.snp.leading)
                make.height.equalTo(KScreenWValue(56))
            }
            
            
            sureBtn.snp.makeConstraints { make in
                make.top.height.equalTo(cancelBtn)
                make.leading.equalTo(verticalLineView.snp.trailing)
                make.trailing.equalToSuperview()
            }
            
            let bottomLineView = UIView()
            mainView.addSubview(bottomLineView)
            bottomLineView.snp.makeConstraints { make in
                make.leading.trailing.equalTo(0)
                make.top.equalTo(sureBtn.snp.bottom)
                make.height.equalTo(0)
            }
            return bottomLineView
        }
        
        if let superView = parentView {
            return dialog.wStartView(superView)

        }
        return dialog.wStart()
    }
}
